using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Magic_Hurt : MonoBehaviour
{
    public float TrapMagicTime = 0.2f;
    public float ContinuousMagicTime = 4f;

    private float HurtCD = 0;
    private float Hurttime = 1f;
    public float Atk_EnemyMagic;
    // Start is called before the first frame update
    void Start()
    {
        if (gameObject.tag == "TrapMagic")
        {
            Collider collider = GetComponent<Collider>();
            Destroy(collider, TrapMagicTime);
            Destroy(gameObject, 1f);
        }
        if (gameObject.tag == "ContinuousMagic")
        {
            Destroy(gameObject, ContinuousMagicTime);
        }
    }
  
    void Update()
    {

        HurtCD -= Time.deltaTime;

    }
    // Update is called once per frame
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Player" ) 
        {
            if(gameObject.tag == "TrapMagic")
            {
                other.gameObject.GetComponent<Player_Control>().GetHurt(Atk_EnemyMagic);
            }
        }

    }
    private void OnTriggerStay(Collider other)
    {
        if (other.gameObject.tag == "Player" && HurtCD < 0)
        {
            if (gameObject.tag == "ContinuousMagic")
            {
                HurtCD = Hurttime;
                other.gameObject.GetComponent<Player_Control>().GetHurt(Atk_EnemyMagic);

            }

        }
    }
}
